package web.controller.sys;

import com.github.pagehelper.PageInfo;
import framework.security.AuthService;
import framework.vo.ResultInfo;
import framework.vo.ResultList;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import system.entity.SysConfig;
import system.service.sys.SysConfigService;

@RestController
@RequestMapping("/sys/config")
@Api(tags = "系统配置")
public class SysConfigController {
    @Autowired
    private SysConfigService sysConfigService;
    @Autowired
    private AuthService authService;
//
//    @ApiOperation("添加系统配置")
//    @PostMapping("/add")
//    public ResultInfo<SysConfig> add(@ModelAttribute SysConfig param) {
//        java.util.Date now = new java.util.Date();
//        param.setCreateTime(now);
//        param.setUpdateTime(now);
//        Integer added = sysConfigService.add(param);
//        ResultInfo<SysConfig> info = new ResultInfo<>(param);
//        return info;
//    }

//    @ApiOperation("删除系统配置")
//    @PostMapping("/del")
//    public ResultInfo<Integer> del(@RequestParam("ids") List<String> ids) {
//        Integer deleted = sysConfigService.deleteByIds(ids);
//        ResultInfo<Integer> info = new ResultInfo<>(deleted);
//        return info;
//    }

    @ApiOperation("更新系统配置")
    @PostMapping("/edit")
    public ResultInfo<Integer> edit(@ModelAttribute SysConfig param) {
        java.util.Date now = new java.util.Date();
        param.setUpdateTime(now);
        Integer updated = sysConfigService.update(param);
        ResultInfo<Integer> info = new ResultInfo<>(updated);
        return info;
    }

    @ApiOperation("查看系统配置")
    @GetMapping("/info")
    public ResultInfo<SysConfig> info(@RequestParam("id") String id) {
        SysConfig info = sysConfigService.loadById(id);
        return new ResultInfo<>(info);
    }

    @ApiOperation("配置列表")
    @GetMapping("/list")
    public ResultList<SysConfig> list(SysConfig param, @RequestParam(value = "pageIndex", defaultValue = "1") Integer pageIndex, @RequestParam(value = "pageSize", defaultValue = "0") Integer pageSize) {
        if (pageSize == 0)
            pageSize = Integer.MAX_VALUE;
        PageInfo<SysConfig> info = sysConfigService.list(param, pageIndex, pageSize);
        return new ResultList<>(info);
    }
}